home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Utilities / Miscellaneous / CopyPaste 3.3.4 / CopyPaste Tools Sourcecode / Selection Sort.c / SortSelection.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-26  |  1.8 KB  |  86 lines  |  [TEXT/KAHL]

  1. /*=========================================================================
  2. Module:        SortSelection
  3.  
  4. Purpose:    Get a selection and sort it.  Then update the selection with
  5.             the sorted selection.
  6.             
  7. returns:    UpdateSel to the scrap.            
  8.  
  9. Functional Details:    
  10.  
  11.             Get a valid selection
  12.             if error
  13.                 exit
  14.             Build the selection into lines of text
  15.             if error
  16.                 exit
  17.             Sort the selection lines
  18.             Update the selection with the sorted lines
  19.             if error
  20.                 exit
  21.             Dispose all allocated storage        
  22.  
  23. =========================================================================*/
  24. #include "ToolSort.h"
  25. #include <SetUpA4.h>
  26.  
  27. void
  28. main()
  29.     {
  30.     SelLine    selLine;        /* Array of handles to selection lines */
  31.     SelRec    validSel;        /* Handle to selection and selection length */
  32.     Text    txt;            /* Handle to selection in text format */
  33.     long     err;
  34.     long    size;
  35.     int        i;
  36.     long    oldA4;
  37.     EvQElPtr    qel;
  38.     
  39.     oldA4=SetUpA4();        /* Globals accessed off of A4 */
  40.     
  41.     GetValidSel( &validSel);
  42.         
  43.     if ( validSel.sel != NIL )
  44.         {
  45.         err = BuildLines(validSel, &selLine);
  46.         DisposHandle( validSel.sel );    /* free memory */
  47.     
  48.         if (selLine.noLines > 0)        /* test 1 line */
  49.             {
  50.             
  51.             Bubble(selLine.lines, sizeof(selLine.lines[0]), 
  52.                                         selLine.noLines, Comp, Swap);
  53.                                         
  54.             err = SelToText( selLine, &txt );
  55.  
  56.             for ( i=0; i<selLine.noLines; i++ )    /* Dispose selLine */
  57.                 {
  58.                 if ( selLine.lines[i] != NIL )
  59.                     {
  60.                     DisposHandle( selLine.lines[i] );
  61.                     selLine.lines[i] = 0L;        /* mark it disposed */
  62.                     }
  63.                 }
  64.             if ( selLine.lines != NIL )
  65.                 {
  66.                 DisposPtr((Ptr)( selLine.lines ));
  67.                 selLine.lines = 0L;                /* mark it disposed */
  68.                 }
  69.  
  70.             if ( txt != NIL )
  71.                 {
  72.                 err = UpdateSel( txt );
  73.                 DisposHandle( txt );
  74.                 
  75.                 }
  76.             }
  77.         }
  78.     
  79.     
  80.     if (PPostEvent(3, 2422, &qel)==noErr)
  81.         {
  82.         qel->evtQModifiers = cmdKey;
  83.         }
  84.     
  85.     RestoreA4(oldA4);            /* restore reg A4 to its original value */
  86.     }